package com.dome.client.config.exception;

import java.util.List;

public class PublicException extends BaseException {
    private static final long serialVersionUID = -1535405572500029548L;
    private int code;
    private List<String> errorList;

    public int getCode() {
        return code;
    }

    public PublicException() {

    }

    /**
     * 将CheckedException转换为UncheckedException.
     */
    public static RuntimeException unchecked(final Exception e) {
        if (e instanceof RuntimeException) {
            return (RuntimeException)e;
        } else {
            return new PublicException(e);
        }
    }

    public PublicException(final String message) {
        super(message);
    }

    public PublicException(final int anCode, final String message) {
        super(anCode, message);
        this.code = anCode;
        this.errorMsg=message;
    }

    public PublicException(final int anCode, final List<String> message) {
        super(anCode, message.get(0));
        this.errorList = message;
        this.code = anCode;
    }

    public PublicException(final Throwable cause) {
        super(cause);
    }

    public PublicException(final String message, final Throwable cause) {
        super(message, cause);
    }

    public PublicException(final int anCode, final String message, final Throwable cause) {
        super(message, cause);
        this.code = anCode;
    }

    public static boolean isCauseLcException(final Exception e) {
        if (e.getCause() != null && e.getCause() instanceof PublicException) {
            return true;
        }
        return false;
    }

    public List<String> getErrorList() {
        return errorList;
    }
}
